﻿@model dai_hoc_tuong_lai.Areas.Admin.Models.NganhHocModel
@{  AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
        OnComplete = "completedAjaxRequest",
        OnBegin = "show_Loading",
    };
}

<script type="text/javascript">

    function completedAjaxRequest(obj) {

        var returnObj = eval('(' + obj.responseText + ')');

        $('#box-busy').fadeOut('medium', function () {
            $('#box-busy').css('display', 'none');
        });

        if (returnObj.Status == "success") {
            if (returnObj.Message != null) {
                makeSuccessHighlight(returnObj.Message);
            }
            else if (returnObj.RedirectUrl != null) {
                window.location.href = returnObj.RedirectUrl;
            }
        } else {
            makeErrorHighlight(returnObj.Message);
        }

        return false;
    }

    function makeErrorHighlight(messageStr) {
        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span><strong>Alert: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area");
        $highlight.delay(4000).fadeOut(500);
    }

    function makeSuccessHighlight(messageStr) {
        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span><strong>Success: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area");
        $highlight.delay(4000).fadeOut(500);
    }



    $(document).ready(function () {

        CKEDITOR.replace('ckeditorId', {
            filebrowserImageUploadUrl: '/Admin/Admin/UploadImage',
            height: "600"
        });

        var thumblogo = $("img#imageslogo");
        var buttonlogo = $("#event-logo-upload")[0];
        var uploader = new qq.FileUploader({
            element: buttonlogo,
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            sizeLimit: 2147483647, // max size
            action: '/Admin/Admin/UploadImageStr',
            multiple: false,
            onSubmit: function (file, extension) {
                //$('div.preview').addClass('loading');
            },
            onComplete: function (id, fileName, responseJSON) {
                $("#idlogopage").val(responseJSON.filePath);
                thumblogo.attr('src', responseJSON.filePath);
                thumblogo.css('display', 'block');
            }
        });

        onlistCategory();

    });

    function onchangeListCatethongtinAdd() {
        var value = $("#ListCatethongtinAdd").val();
        $("#cateIdCode").val(value);
    }


    function onlistCategory() {
        var valueID = $("#ParentIdCode").val();
        var selectOn = false;
        $.getJSON("/Admin/NganhHoc/AllCategories", { selectedId: 0 },
            function (carData) {
                var select = $("#selectCate");
                select.empty();
                $.each(carData, function (index, itemData) {
                    if (itemData.Value == valueID)
                        selectOn = true;
                    else
                        selectOn = false;
                    select.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text,
                        selected: selectOn
                    }));
                });
            });

    }

    function onchangeselectCate() {
        var value = $("#selectCate").val();
        $("#ParentIdCode").val(value);
    }

</script>
<div class="pageManager">
    @using (Ajax.BeginForm("AddOrUpdate", "HinhAnh", null, ajaxOpts, new { enctype = "multipart/form-data" }))
    {
        <div class="section-header">
            <dl class="submit">
                <img class="NFButtonLeft" src="img/0.png" style="border: 0" />
                <input type="submit" name="submit" id="submit" value="Submit" class="NFButton">
                <img src="img/0.png" class="NFButtonRight" style="border: 0" />
            </dl>
        </div>
        <div id="tabasAddCategory">
            <div id="tabs-1">
                <table>
                    <tr>
                        <td colspan="2">
                            @Html.HiddenFor(model => model.Id, new { id = "Id" })
                            @Html.HiddenFor(model => model.DateCreate)
                            @Html.HiddenFor(model => model.Anh, new { id = "idlogopage" })
                            @Html.HiddenFor(model => model.Cate_Id, new { id = "ParentIdCode" })
                            <div class="warning-area">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.LabelFor(model => model.Cate_Id, "Chọn chuyên mục"):
                        </td>
                        <td class="adminData">
                            <select id="selectCate" onchange="onchangeselectCate();" class="listCate" style="width: 400px;">
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.LabelFor(model => model.Title, "Tiêu đề ngành học"):
                        </td>
                        <td class="adminData">
                            @Html.TextBoxFor(model => Model.Title, new { @style = "width:580px" })
                            @Html.ValidationMessageFor(model => model.Title)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.LabelFor(model => model.Noidung, "Nội dung"):
                        </td>
                        <td class="adminData">
                            @Html.TextAreaFor(model => Model.Noidung, new { @class = "ckeditorId", id = "ckeditorId" })
                            @Html.ValidationMessageFor(model => model.Noidung)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.LabelFor(model => model.Anh, "Ảnh đại diện"):
                        </td>
                        <td class="adminData">
                            <div id="event-logo-upload" style="">
                            </div>
                            <img src="@Model.Anh" id="imageslogo" width="100px" height="70px" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    }
</div>
